package mapa;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class Posicion {
	
	private int posX;
	private int posY;
	
	public Posicion(int x, int y){
		this.posX = x;
		this.posY = y;
	}
	
	public int getPosX(){
		return this.posX;
	}
	
	public int getPosY(){
		return this.posY;
	}

	public void restarEnY(int cantCondenadas) {
		this.posY = posY - cantCondenadas;		
	}
	
	public void restarEnX(int cantCondenadas) {
		this.posX = posX - cantCondenadas;		
	}

	public void sumarEnY(int cantCondenadas) {
		this.posY = posY + cantCondenadas;
	}
	
	public void sumarEnX(int cantCondenadas) {
		this.posX = posX + cantCondenadas;
	}

	public Node serializar(Document dom) {
		
		Element element = dom.createElement("Posicion");
		element.setAttribute("posX", ((Integer)posX).toString());
		element.setAttribute("posY", ((Integer)posY).toString());
		
		return element;
	}

	public static Posicion deserializar(Node nodo) {
	
		return new Posicion(Integer.parseInt(nodo.getAttributes().getNamedItem("posX").getTextContent()),
				Integer.parseInt(nodo.getAttributes().getNamedItem("posY").getTextContent()));
	}		
}
